//
//  LockerVC.m
//  抽屉
//
//  Created by 李劲成 on 16/5/26.
//  Copyright © 2016年 ljc. All rights reserved.
//

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
#define IF_IOS7_OR_GREATER(...) \
if (kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber_iOS_6_1) \
{ \
__VA_ARGS__ \
}
#else
#define IF_IOS7_OR_GREATER(...)
#endif
#import "LockerVC.h"

@interface LockerVC ()
/** 背景视图 */
@property (strong, nonatomic) UIImageView *backgroundImageView;
/** 内容界面是否显示 */
@property (assign, nonatomic) BOOL visible;
/** 抽屉栏是否显示 */
@property (assign, nonatomic) BOOL leftMenuVisible;
/** 原点 */
@property (assign, nonatomic) CGPoint originalPoint;
/** 目录界面 */
@property (strong, nonatomic) UIView *menuViewContainer;
/** 主界面 */
@property (strong, nonatomic) UIView *contentViewContainer;

@property (assign, nonatomic) BOOL didNotifyDelegate;
/** 内容容器上的 Button 点击可隐藏菜单栏 */
@property (strong, readwrite, nonatomic) UIButton *contentButton;
@end

@implementation LockerVC

#pragma mark -- 重写初始化
- (instancetype)init{
    self = [super init];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)decoder
{
    self = [super initWithCoder:decoder];
    if (self) {
        [self commonInit];
    }
    return self;
}

#pragma mark - 默认设置
- (void)commonInit{
    _menuViewContainer = [[UIView alloc]init];
    _contentViewContainer = [[UIView alloc]init];
    // 设置动画间隔初值
    _animationDuration = 0.35;
    _interactivePopGestureRecognizerEnabled = YES;
    // 设置手势触摸初值
    _panGestureEnabled = YES;
    _panFromEdge = YES;
    _panMinimumOpenThreshold = 60.0;
    //设置菜单视图比例变成1.5倍
     _menuViewControllerTransformation = CGAffineTransformMakeScale(1.5f, 1.5f);
    
     _scaleContentView = YES;
    // 设置背景视图开启比例
    _scaleBackgroundImageView = YES;
    // 设置菜单视图开启比例
    _scaleMenuView = YES;
    // 设置菜单视图逐渐消失
    _fadeMenuView = YES;
    
    // 水平回弹默认
    _bouncesHorizontally = YES;
    
    _contentViewFadeOutAlpha = 1.0f;
    
    _contentViewInLandscapeOffsetCenterX = 30.f;
    
    _contentViewInPortraitOffsetCenterX  = 30.f;
    
    _contentViewScaleValue = 0.75f;
}

#pragma mark -
#pragma mark Public methods
#pragma mark - 初始化
- (id)initWithContentViewController:(UIViewController *)contentViewController leftMenuViewController:(UIViewController *)leftMenuViewController {
    self = [self init];
    if (self) {
        // 左侧视图
        _contentViewController = contentViewController;
        _leftMenuViewController = leftMenuViewController;
    
    }
    return self;
}

- (void)presentLeftMenuViewController
{
    [self presentMenuViewContainerWithMenuViewController:self.leftMenuViewController];
    [self showMenuViewController];
}

- (void)hideMenuViewController
{
    [self hideMenuViewControllerAnimated:YES];
}

- (void)setContentViewController:(UIViewController *)contentViewController animated:(BOOL)animated
{
    // 判断如果相同, 则返回
    if (_contentViewController == contentViewController)
    {
        return;
    }
    // 判断是否动画
    if (!animated) {
        
        [self setContentViewController:contentViewController];
    } else {
        // 添加孩子控制器(持久化)
        [self addChildViewController:contentViewController];
        // 内容视图透明度为0
        contentViewController.view.alpha = 0;
        // 设置为内容容器的大小
        contentViewController.view.frame = self.contentViewContainer.bounds;
        // 将设置的内容视图 添加到内容容器上.
        [self.contentViewContainer addSubview:contentViewController.view];
        // 动画
        [UIView animateWithDuration:self.animationDuration animations:^{
            // 透明度渐变到1
            contentViewController.view.alpha = 1;
        } completion:^(BOOL finished) {
            // 隐藏视图控制器
            [self hideViewController:self.contentViewController];
            // 移除孩子控制器
            [contentViewController didMoveToParentViewController:self];
            // 指针指向
            _contentViewController = contentViewController;
            
            
       }];
    }

}

#pragma mark View life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // 自适应
     self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    // 背景图
    self.backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _backgroundImageView.image = self.backgroundImage;
        // 铺满
        _backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
        // 自适应
        _backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.contentButton = [[UIButton alloc] initWithFrame:CGRectNull];
        [_contentButton addTarget:self action:@selector(hideMenuViewController) forControlEvents:UIControlEventTouchUpInside];

 
    [self.view addSubview:self.backgroundImageView];
    [self.view addSubview:self.menuViewContainer];
    [self.view addSubview:self.contentViewContainer];
    
    // 设置菜单容器大小
    _menuViewContainer.frame = self.view.bounds;
    _menuViewContainer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
    
    if (self.leftMenuViewController) {
        // 添加孩子控制器
        [self addChildViewController:_leftMenuViewController];
        _leftMenuViewController.view.frame = self.view.bounds;
        _leftMenuViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        // 添加到菜单容器
        [self.menuViewContainer addSubview:_leftMenuViewController.view];
        // 移除父视图控制器
        [self.leftMenuViewController didMoveToParentViewController:self];
    }
    
    self.contentViewContainer.frame = self.view.bounds;
    self.contentViewContainer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self addChildViewController:_contentViewController];
    self.contentViewController.view.frame = self.view.bounds;
    [self.contentViewContainer addSubview:self.contentViewController.view];
    [self.contentViewController didMoveToParentViewController:self];
    
    self.menuViewContainer.alpha = !self.fadeMenuView ?: 0;
    if (self.scaleBackgroundImageView){
        self.backgroundImageView.transform = CGAffineTransformMakeScale(1.7f, 1.7f);
    }
    
    // 添加手势
    if (self.panGestureEnabled) {
        self.view.multipleTouchEnabled = NO;
        UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
        panGestureRecognizer.delegate = self;
        [self.view addGestureRecognizer:panGestureRecognizer];
    }
    // Do any additional setup after loading the view.
}
#pragma mark - private methods

#pragma mark - 推出菜单控制器
- (void)presentMenuViewContainerWithMenuViewController:(UIViewController *)menuViewController{
    // 重置 Transform
    self.menuViewContainer.transform = CGAffineTransformIdentity;
    // 判断背景图片的比例是否被改变
    if (_scaleBackgroundImageView) {
        _backgroundImageView.transform = CGAffineTransformIdentity;
        _backgroundImageView.frame = self.view.bounds;
    }
    // 设置菜单容器界面大小
     self.menuViewContainer.frame = self.view.bounds;
    // 判断菜单视图比例是否被改变.
    if (self.scaleMenuView) {
        self.menuViewContainer.transform = self.menuViewControllerTransformation;
    }
    //设置菜单容器视图的透明度(根据 fadeMenuView)
     _menuViewContainer.alpha = !self.fadeMenuView ?: 0;
    // 判断背景视图更改比例
    if (self.scaleBackgroundImageView){
        self.backgroundImageView.transform = CGAffineTransformMakeScale(1.7f, 1.7f);
    }
    // 通知代理人将要显示菜单栏
    if ([self.delegate conformsToProtocol:@protocol(LocalVCDelegate)] && [self.delegate respondsToSelector:@selector(locker:willShowMenuViewController:)]) {
        [self.delegate locker:self willShowMenuViewController:menuViewController];
    }

    
}

#pragma mark - 显示菜单视图
- (void)showMenuViewController{
    // 若不存在则返回
    if (!_leftMenuViewController) {
        return;
    }
    // 通知孩子控制器改变界面。
    [_leftMenuViewController beginAppearanceTransition:YES animated:YES];
    _leftMenuViewController.view.hidden = NO;
    // 结束编辑
    [self.view.window endEditing:YES];
      // 添加隐藏菜单栏的 Button
     [self addContentButton];
    // 重置内容视图比例
    [self resetContentViewScale];
    // 动画显示
    [UIView animateWithDuration:_animationDuration animations:^{
        // 判断内容视图是否显示比例
        if (self.scaleContentView) {
            self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue);
        } else {
            self.contentViewContainer.transform = CGAffineTransformIdentity;
        }
      // 判断版本, 改变内容视图中心
        
        if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
            // 判断现在为横竖屏
            self.contentViewContainer.center = CGPointMake((UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) ? _contentViewInLandscapeOffsetCenterX + CGRectGetWidth(self.view.frame) : _contentViewInPortraitOffsetCenterX + CGRectGetWidth(self.view.frame) /1.1), _contentViewContainer.center.y);
        } else {
            self.contentViewContainer.center = CGPointMake((UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) ? _contentViewInLandscapeOffsetCenterX + CGRectGetHeight(self.view.frame) : _contentViewInPortraitOffsetCenterX + CGRectGetWidth(self.view.frame) / 1.1), self.contentViewContainer.center.y);
        }

               _menuViewContainer.alpha = !self.fadeMenuView ?: 1.0f;
               // 重置菜单视图比例
                _menuViewContainer.transform = CGAffineTransformIdentity;
        if (_scaleBackgroundImageView){
            // 重置背景图比例
            self.backgroundImageView.transform = CGAffineTransformIdentity;
        }
        
    }completion:^(BOOL finished) {
        [self.leftMenuViewController endAppearanceTransition];
         // 通知代理人已经显示菜单栏
        if (!self.visible && [self.delegate conformsToProtocol:@protocol(LocalVCDelegate)] && [self.delegate respondsToSelector:@selector(locker:didShowMenuViewController:)]) {
            [self.delegate locker:self didShowMenuViewController:_leftMenuViewController];
        }
        
        self.visible = YES;
        // 记录左侧视图已经显示
        self.leftMenuVisible = YES;
    }];
}

#pragma mark - 隐藏视图控制器
- (void)hideViewController:(UIViewController *)viewController
{
    [viewController willMoveToParentViewController:nil];
    [viewController.view removeFromSuperview];
    [viewController removeFromParentViewController];
}

- (void)addContentButton
{
    if (self.contentButton.superview)
        return;
    
    self.contentButton.autoresizingMask = UIViewAutoresizingNone;
    self.contentButton.frame = self.contentViewContainer.bounds;
    self.contentButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.contentViewContainer addSubview:self.contentButton];
}

#pragma mark - 重置内容视图比例
- (void)resetContentViewScale
{
    // 记录当前 transform
    CGAffineTransform t = self.contentViewContainer.transform;
    CGFloat scale = sqrt(t.a * t.a + t.c * t.c);
    CGRect frame = self.contentViewContainer.frame;
    // 重置容器视图属性
    self.contentViewContainer.transform = CGAffineTransformIdentity;
    self.contentViewContainer.transform = CGAffineTransformMakeScale(scale, scale);
    self.contentViewContainer.frame = frame;
}


#pragma mark - 隐藏菜单视图
- (void)hideMenuViewControllerAnimated:(BOOL)animated
{
 
    [_leftMenuViewController beginAppearanceTransition:NO animated:animated];
    if ([self.delegate conformsToProtocol:@protocol(LocalVCDelegate)] && [self.delegate respondsToSelector:@selector(locker:willHideMenuViewController:)]) {
        [self.delegate locker:self willHideMenuViewController:_leftMenuViewController];
    }
    self.visible = NO;
    self.leftMenuVisible = NO;
    [self.contentButton removeFromSuperview];
    __typeof (self) __weak weakSelf = self;
    // 动画
    void (^animationBlock)(void) = ^{
        __typeof (weakSelf) __strong strongSelf = weakSelf;
        if (!strongSelf) {
            return;
        }
        // 重置内容容器视图属性
        strongSelf.contentViewContainer.transform = CGAffineTransformIdentity;
        strongSelf.contentViewContainer.frame = strongSelf.view.bounds;
        // 重置菜单容器视图属性
        if (strongSelf.scaleMenuView) {
            
            strongSelf.menuViewContainer.transform = strongSelf.menuViewControllerTransformation;
        }
        strongSelf.menuViewContainer.alpha = !self.fadeMenuView ?: 0;
        strongSelf.contentViewContainer.alpha = 1;
        
        if (strongSelf.scaleBackgroundImageView) {
            strongSelf.backgroundImageView.transform = CGAffineTransformMakeScale(1.7f, 1.7f);
        }
    };
    // 完成
    void (^completionBlock)(void) = ^{
        __typeof (weakSelf) __strong strongSelf = weakSelf;
        if (!strongSelf) {
            return;
        }
        [_leftMenuViewController endAppearanceTransition];
        if (!strongSelf.visible && [strongSelf.delegate conformsToProtocol:@protocol( LocalVCDelegate)] && [strongSelf.delegate respondsToSelector:@selector(locker:didHideMenuViewController:)]) {
            [strongSelf.delegate locker:self didHideMenuViewController:_leftMenuViewController];
        }
    };
    // 判断是否动画效果
    if (animated) {
        // 暂停处理相关事件
        [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
        [UIView animateWithDuration:self.animationDuration animations:^{
            animationBlock();
        } completion:^(BOOL finished) {
            [[UIApplication sharedApplication] endIgnoringInteractionEvents];
            completionBlock();
        }];
    } else {
        animationBlock();
        completionBlock();
    }

    
}

#pragma mark -
#pragma mark UIGestureRecognizer Delegate (Private)

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    IF_IOS7_OR_GREATER(
                       if (self.interactivePopGestureRecognizerEnabled && [self.contentViewController isKindOfClass:[UINavigationController class]]) {
                           UINavigationController *navigationController = (UINavigationController *)self.contentViewController;
                           if (navigationController.viewControllers.count > 1 && navigationController.interactivePopGestureRecognizer.enabled) {
                               return NO;
                           }
                       }
                       );
    
    if (self.panFromEdge && [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && !self.visible) {
        CGPoint point = [touch locationInView:gestureRecognizer.view];
        if (point.x < 50.0) {
            return YES;
        } else {
            return NO;
        }
    }
    
    return YES;
}

#pragma mark -
#pragma mark Pan gesture recognizer (Private)

- (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer
{
    CGPoint point = [recognizer translationInView:self.view];
    
    if (recognizer.state == UIGestureRecognizerStateBegan) {
    
        self.originalPoint = CGPointMake(self.contentViewContainer.center.x - CGRectGetWidth(self.contentViewContainer.bounds) / 2.0,
                                         self.contentViewContainer.center.y - CGRectGetHeight(self.contentViewContainer.bounds) / 2.0);
        self.menuViewContainer.transform = CGAffineTransformIdentity;
        if (self.scaleBackgroundImageView) {
            self.backgroundImageView.transform = CGAffineTransformIdentity;
            self.backgroundImageView.frame = self.view.bounds;
        }
        self.menuViewContainer.frame = self.view.bounds;
        [self addContentButton];
        [self.view.window endEditing:YES];
        self.didNotifyDelegate = NO;
    }
    if (recognizer.state == UIGestureRecognizerStateChanged) {
        CGFloat delta = 0;
        // 判断显示
        if (self.visible) {
            // 中间变量记录比例
            delta = self.originalPoint.x != 0 ? (point.x + self.originalPoint.x) / self.originalPoint.x : 0;
        } else {
            delta = point.x / self.view.frame.size.width;
        }
        // 求浮点数x的绝对值
        delta = MIN(fabs(delta), 1.6);
        // 中间变量记录
        CGFloat contentViewScale = self.scaleContentView ? 1 - ((1 - self.contentViewScaleValue) * delta) : 1;
        
        CGFloat backgroundViewScale = 1.7f - (0.7f * delta);
        CGFloat menuViewScale = 1.5f - (0.5f * delta);
        
        if (!self.bouncesHorizontally) {
            // 取最大值
            contentViewScale = MAX(contentViewScale, self.contentViewScaleValue);
            backgroundViewScale = MAX(backgroundViewScale, 1.0);
            menuViewScale = MAX(menuViewScale, 1.0);
        }

        self.menuViewContainer.alpha = !self.fadeMenuView ?: delta;
        self.contentViewContainer.alpha = 1 - (1 - self.contentViewFadeOutAlpha) * delta;
        
        if (self.scaleBackgroundImageView) {
            self.backgroundImageView.transform = CGAffineTransformMakeScale(backgroundViewScale, backgroundViewScale);
        }
        
        if (self.scaleMenuView) {
            self.menuViewContainer.transform = CGAffineTransformMakeScale(menuViewScale, menuViewScale);
        }
        
        if (self.scaleBackgroundImageView) {
            if (backgroundViewScale < 1) {
                self.backgroundImageView.transform = CGAffineTransformIdentity;
            }
        }
        if (!self.bouncesHorizontally && self.visible) {
            if (self.contentViewContainer.frame.origin.x > self.contentViewContainer.frame.size.width / 2.0)
                point.x = MIN(0.0, point.x);
            
            if (self.contentViewContainer.frame.origin.x < -(self.contentViewContainer.frame.size.width / 2.0))
                point.x = MAX(0.0, point.x);
        }
        // Limit size
        //
        if (point.x < 0) {
            point.x = MAX(point.x, -[UIScreen mainScreen].bounds.size.height);
        } else {
            point.x = MIN(point.x, [UIScreen mainScreen].bounds.size.height);
        }
        [recognizer setTranslation:point inView:self.view];
        
        if (!self.didNotifyDelegate) {
            if (point.x > 0) {
                if (!self.visible && [self.delegate conformsToProtocol:@protocol(LocalVCDelegate)] && [self.delegate respondsToSelector:@selector(locker:didShowMenuViewController:)]) {
                    [self.delegate locker:self willShowMenuViewController:_leftMenuViewController];
                }
            }
            self.didNotifyDelegate = YES;
        }
        if (contentViewScale > 1) {
            CGFloat oppositeScale = (1 - (contentViewScale - 1));
            self.contentViewContainer.transform = CGAffineTransformMakeScale(oppositeScale, oppositeScale);
            self.contentViewContainer.transform = CGAffineTransformTranslate(self.contentViewContainer.transform, point.x, 0);
        } else {
            self.contentViewContainer.transform = CGAffineTransformMakeScale(contentViewScale, contentViewScale);
            self.contentViewContainer.transform = CGAffineTransformTranslate(self.contentViewContainer.transform, point.x, 0);
        }
        
          self.leftMenuViewController.view.hidden = self.contentViewContainer.frame.origin.x < 0;
        if (!self.leftMenuViewController && self.contentViewContainer.frame.origin.x > 0) {
            self.contentViewContainer.transform = CGAffineTransformIdentity;
            self.contentViewContainer.frame = self.view.bounds;
            self.visible = NO;
            self.leftMenuVisible = NO;
        }


    }
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        self.didNotifyDelegate = NO;
        if (self.panMinimumOpenThreshold > 0 && (
                                                 (self.contentViewContainer.frame.origin.x < 0 && self.contentViewContainer.frame.origin.x > -((NSInteger)self.panMinimumOpenThreshold)) ||
                                                 (self.contentViewContainer.frame.origin.x > 0 && self.contentViewContainer.frame.origin.x < self.panMinimumOpenThreshold))
            ) {
            [self hideMenuViewController];
        }
        else if (self.contentViewContainer.frame.origin.x == 0) {
            [self hideMenuViewControllerAnimated:NO];
        }
        else {
            if ([recognizer velocityInView:self.view].x > 0) {
                if (self.contentViewContainer.frame.origin.x < 0) {
                    [self hideMenuViewController];
                } else {
                    if (self.leftMenuViewController) {
                        [self showMenuViewController];
                    }
                }
            }
        }
    }

}

#pragma mark - 重写 set
- (void)setBackgroundImage:(UIImage *)backgroundImage
{
    _backgroundImage = backgroundImage;
    if (self.backgroundImageView)
        self.backgroundImageView.image = backgroundImage;
}
- (void)setContentViewController:(UIViewController *)contentViewController
{
    if (!_contentViewController) {
        _contentViewController = contentViewController;
        return;
    }
    [self hideViewController:_contentViewController];
    _contentViewController = contentViewController;
    
    [self addChildViewController:self.contentViewController];
    self.contentViewController.view.frame = self.view.bounds;
    [self.contentViewContainer addSubview:self.contentViewController.view];
    [self.contentViewController didMoveToParentViewController:self];
    
}

- (void)setLeftMenuViewController:(UIViewController *)leftMenuViewController
{
    if (!_leftMenuViewController) {
        _leftMenuViewController = leftMenuViewController;
        return;
    }
    [self hideViewController:_leftMenuViewController];
    _leftMenuViewController = leftMenuViewController;
    
    [self addChildViewController:self.leftMenuViewController];
    self.leftMenuViewController.view.frame = self.view.bounds;
    self.leftMenuViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.menuViewContainer addSubview:self.leftMenuViewController.view];
    [self.leftMenuViewController didMoveToParentViewController:self];
    [self.view bringSubviewToFront:self.contentViewContainer];
}

#pragma mark -
#pragma mark View Controller Rotation handler

- (BOOL)shouldAutorotate
{
    return self.contentViewController.shouldAutorotate;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (self.visible) {
        self.menuViewContainer.bounds = self.view.bounds;
        self.contentViewContainer.transform = CGAffineTransformIdentity;
        self.contentViewContainer.frame = self.view.bounds;
        
        if (self.scaleContentView) {
            self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue);
        } else {
            self.contentViewContainer.transform = CGAffineTransformIdentity;
        }
        
        CGPoint center;
        if (self.leftMenuVisible) {
            if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
                center = CGPointMake((UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? self.contentViewInLandscapeOffsetCenterX + CGRectGetWidth(self.view.frame) : self.contentViewInPortraitOffsetCenterX + CGRectGetWidth(self.view.frame)), self.contentViewContainer.center.y);
            } else {
                center = CGPointMake((UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? self.contentViewInLandscapeOffsetCenterX + CGRectGetHeight(self.view.frame) : self.contentViewInPortraitOffsetCenterX + CGRectGetWidth(self.view.frame)), self.contentViewContainer.center.y);
            }
        } else {
            center = CGPointMake((UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? -self.contentViewInLandscapeOffsetCenterX : -self.contentViewInPortraitOffsetCenterX), self.contentViewContainer.center.y);
        }
        
        self.contentViewContainer.center = center;
    }
    
}

#pragma mark -
#pragma mark Status Bar Appearance Management

- (UIStatusBarStyle)preferredStatusBarStyle
{
    UIStatusBarStyle statusBarStyle = UIStatusBarStyleDefault;
    IF_IOS7_OR_GREATER(
                       statusBarStyle = self.visible ? self.menuPreferredStatusBarStyle : self.contentViewController.preferredStatusBarStyle;
                       if (self.contentViewContainer.frame.origin.y > 10) {
                           statusBarStyle = self.menuPreferredStatusBarStyle;
                       } else {
                           statusBarStyle = self.contentViewController.preferredStatusBarStyle;
                       }
                       );
    return statusBarStyle;
}

- (BOOL)prefersStatusBarHidden
{
    BOOL statusBarHidden = NO;
    IF_IOS7_OR_GREATER(
                       statusBarHidden = self.visible ? self.menuPrefersStatusBarHidden : self.contentViewController.prefersStatusBarHidden;
                       if (self.contentViewContainer.frame.origin.y > 10) {
                           statusBarHidden = self.menuPrefersStatusBarHidden;
                       } else {
                           statusBarHidden = self.contentViewController.prefersStatusBarHidden;
                       }
                       );
    return statusBarHidden;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
    UIStatusBarAnimation statusBarAnimation = UIStatusBarAnimationNone;
    IF_IOS7_OR_GREATER(
                       statusBarAnimation = self.visible ? self.leftMenuViewController.preferredStatusBarUpdateAnimation : self.contentViewController.preferredStatusBarUpdateAnimation;
                       if (self.contentViewContainer.frame.origin.y > 10) {
                           statusBarAnimation = self.leftMenuViewController.preferredStatusBarUpdateAnimation;
                       } else {
                           statusBarAnimation = self.contentViewController.preferredStatusBarUpdateAnimation;
                       }
                       );
    return statusBarAnimation;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
